<?php
namespace app\admin\model;
use think\Model;

class ShopLists extends Model{
    // protected $table = 'oyk_shop_cat';
    protected $name = 'shop_cat';
    protected $pk = 'cid';
    protected $schema = [
        'cid' => 'int',
        'pid' => 'int',
        'name' => 'string',
        'pic' => 'string',
        'sort' => 'int',
        'status' => 'int',
    ];

    // protected $disuse = [
    //     'pic',
    //     'status'
    // ];

    public function get_data(){
        // $ret = ShopLists::find(6);
        // $ret = ShopLists::where('id',10)->find();

        $ret = static::select();
        
        // return $ret;
        return $ret->toArray();
    }
    // 获取器
    public function getStatusAttr($v){
        print_r($v);
        if($v == 1){
            $name = '开启';
        }else if($v == 0){
            $name = '关闭';
        }else if($v == 2){
            $name = '审核';
        }
        return $name;
    }
    // 修改数据
    public function set_data(){
        $create = ShopLists::create([
            'pid' => 21,
            'name' => '打印机',
            'pic' => 'https://img13.360buyimg.com/focus/s140x140_jfs/t11284/298/2465125571/2619/ffe2cde5/5a17f237Nb9978251.jpg',
            'sort' => 0,
            'status' => 1
        ]);

        return $create;
    }

    // 修改器
    public function setNameAttr($v,$all){
        print_r($v);

        if($v == '打印机'){
            return 'php' . $v;
        }
    }

    public function search_data(){
        $ret = ShopLists::withSearch(
            ["name"],
            ["name" => '三']
        )->select();
        return $ret;
    }

    public function searchNameAttr($query,$v){
        // print_r($query);
        print_r($v);
        $query->where('name','like','%'.$v.'%');
    }

    public static function onAfterRead(){
        echo 111;
        // 可以在这里做 保存日志，作为用户的操作分析
    }
}